package com.example.oj_springboot.controller;

import com.example.oj_springboot.api.CompileRest;
import com.example.oj_springboot.api.config.exception.CodeNullException;
import com.example.oj_springboot.model.CompileRequest;
import com.example.oj_springboot.model.CompileResponse;
import com.example.oj_springboot.service.CompileService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CompileController implements CompileRest {

    @Autowired
    private CompileService compileService;

    @Override
    public CompileResponse compile(@RequestBody CompileRequest compileRequest) throws Exception {
        if (StringUtils.isBlank(compileRequest.getCode())){
            throw new CodeNullException();
        }
        return compileService.compile(compileRequest);
    }
}